<template>
  <div>
    <el-dialog ref="modalFrame"
               title="发起申诉"
               center
               :visible.sync="innerVisible"
               width="800px"
    >
      <el-form ref="form" :model="model" label-width="112px">
        <el-row>
          <el-col :span="24">
            <el-form-item prop="memo" label="申诉说明:"
                          :rules="[
                                {required: true, message: '申诉说明必须', trigger: 'change'}
                              ]"
            >
              <el-input type="textarea" :rows="5" v-model="model.memo" placeholder="请输入申诉说明"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item
              label="申诉附件"
              prop="picture"
              :rules="{
                    required: true, message: '图片必须', trigger: 'change', type: 'array'
                  }"
            >
              <upload-image v-model="model.picture" :formData="{group: id}" :max="2" :singleMaxSize="524288"></upload-image>
              <span class="font-red">建议上传图片分辨率为 750x1334（正常二倍）,大小不超过0.5M</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button type="primary" :loading="loading" @click.prevent="submitFollowUp"> 确认发起申诉</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {copy} from '@/utils'
export default {
  name: 'baseFollowUp',
  components: {},
  filters: {},
  props: {
    id: {
      type: String,
      required: true
    },
    visible: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      innerVisible: false,
      loading: false,
      model: {
        memo: '',
        picture: []
      }
    }
  },
  watch: {
    visible(val, oldVal) {
      console.log('val', val)
      if (val === oldVal) {
        return
      }
      this.innerVisible = val
    },
    innerVisible(val, oldVal) {
      if (val === oldVal) {
        return
      }
      this.$emit('update:visible', val)
    }
  },
  methods: {
    submitFollowUp() {
      this.$refs.form.validate().then(result => {
        if (result === false) {
          return
        }
        let data = copy(this.model, true)
        data.orderId = this.id
        this.loading = true
        this.$ajax.post('/ms-fahuobao-order/merRefund/applyArbitrationRefund', data).then(response => {
          this.loading = false
          if (response.success) {
            this.innerVisible = false
            this.$confirm('申诉成功', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'success'
            }).then(() => {
              this.$router.push({path: '/ss-fhb/refund/index'})
            })
          }
        })
      })
    }
  }
}
</script>
